<?php
/*********************/
/*                   */
/*  批发申请模块       */
/*   enjoying7       */
/*  2009-4-7         */
/*                   */
/*********************/

include_once( "shopObject.php" );
class mdl_pifa extends shopobject
{

	var $idColumn = "id";
	var $textColumn = "truename";
	var $tableName = "sdb_add_pifa";
	var $defaultCols = "regtime,pifatype,truename,userid,status";
	var $defaultOrder = array
	(
		0 => "id",
		1 => " DESC",
		2 => ",regtime",
		3 => " DESC"
	);

	function searchoptions( )
	{
		return array( "username" => "用户名", "truename" => "姓名" );
	}

	function getcolumns( )
	{
		return array(
			"id" => array( "label" => "ID", "class" => "span-4" ),
			"username" => array( "label" => "用户名", "class" => "span-3" ),
			"pifatype" => array( "label" => "申请类别", "class" => "span-3", "type" => "object:member" ),
			"truename" => array( "label" => "姓名", "class" => "span-8", "type" => "ship_name", "fuzzySearch" => 1 ),
			"status" => array( "label" => "处理状态", "class" => "span-2", "type" => "ship_status" ),
			"regtime" => array( "label" => "申请时间", "class" => "span-3", "type" => "time:FDATE_STIME" )
		);
	}


	function get_status( $status )
	{
		switch ( $status )
		{
		case 1 :
			$status = "申请中";
			return $status;
		case 2 :
			$status = "审核中";
			return $status;
		case 3 :
			$status = "接受申请";
			return $status;
		case 4 :
			$status = "完成";
			return $status;
		case 5 :
			$status = "申请失败";
		}
		return $status;
	}

	function load( $id )
	{
		if ( $row = $this->db->selectrow( "SELECT * from sdb_add_pifa where id =".$id ) )
		{
			$this->_info['id'] = $row['id'];
			$this->_info['userid'] = $row['userid'];
			$this->_info['pifatype'] = $row['pifatype'];
			$this->_info['username'] = $row['username'];
			$this->_info['truename'] = $row['truename'];
			$this->_info['status'] = $this->get_status( $row['status'] );
			$this->_info['status_int'] = $row['status'];
			$this->_info['sf_no'] = $row['sf_no'];
			$this->_info['regtime'] = $row['regtime'];
			$this->_info['mobile'] = $row['mobile'];
			if ( $row['shenfen'] )
			{
				$this->_info['shenfen'] = $row['shenfen'];
			}
			
			return $this->_info;
		}
		return false;
	}
	
	function check_sf_no($sf_no)
	{
		$row = $this->db->selectrow( "select sf_no from sdb_add_pifa where sf_no='".$sf_no."'" );
		if ( $row['sf_no'] == $sf_no )
		{
			
			return true;
		}
		else return false;
	
	}
	function check_userid($userid)
	{
		$row = $this->db->selectrow( "select userid from sdb_add_pifa where userid='".$userid."'" );
		if ( $row['userid'] == $userid )
		{
			
			return true;
		}
		else return false;
	
	}
	function check_online_addr($online_addr)
	{
		$row = $this->db->selectrow( "select online_addr from sdb_add_pifa where online_addr='".$online_addr."'" );
		if ( $row['online_addr'] == $online_addr )
		{
			
			return true;
		}
		else return false;
	
	}
	function check_entity_addr($entity_addr)
	{
		$row = $this->db->selectrow( "select online_addr from sdb_add_pifa where entity_addr='".$entity_addr."'" );
		if ( $row['entity_addr'] == $entity_addr )
		{
			
			return true;
		}
		else return false;
	
	}
	
	function getmemberbyid( $member_id )
	{
		return $this->db->select( "SELECT * FROM sdb_members where member_id = '".$member_id."'" );
	}
	
	function change_status( $id, $status )
	{
		$data = array(
			"status" => $status
		);
		$filter = array(
			"id" => $id
		);
		if ( $this->update( $data, $filter ) )
		{
			return $this->get_status( $status );
		}
	}

	function modifier_ship_name( &$rows )
	{
		foreach ( $rows as $k => $v )
		{
			$rows[$k] = htmlspecialchars( $rows[$k], ENT_QUOTES );
		}
	}

	
	function save( $aData )
	{
		$rs = $this->db->query( "select * from sdb_add_pifa where 0=1" );
		$sqlString = $this->db->getinsertsql( $rs, $aData );
		if ( $this->db->exec( $sqlString ) )
		{
			return true;
		}
		return false;
	}

	function file_download( $filename )
	{
		$file = fopen( $filename, "r" );
		header( "Content-type: application/octet-stream" );
		header( "Accept-Ranges: bytes" );
		header( "Accept-Length: ".filesize( $filename ) );
		header( "Content-Disposition: attachment; filename=".basename( $filename ) );
		echo fread( $file, filesize( $filename ) );
		fclose( $file );
	}

}

?>
